home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
readobj.zip
/
READOBJ.C
< prev
next >
Wrap
Text File
|
1987-10-07
|
26KB
|
1,028 lines
/****************************************************************
* name readobj -- read and format obj files *
* into a printable output *
* *
* Original by Kip Davidson (73247,620) *
* Upgraded to handle OS/2 object & libs by Dave Cortesi (72155,450) *
* *
* usage readobj filename *
* *
* where "filename" is the name of an object code *
* file, e.g. ROB.OBJ, or else the name of an *
* object library, e.g. DOSCALLS.LIB. *
* *
****************************************************************/
/****************
* Include files *
*****************/
#define LINT_ARGS
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
/********************************
* Microsoft Object Record Types *
********************************/
#define BLKDEF 0x7A
#define BLKEND 0x7C
#define THEADR 0x80
#define COMENT 0x88
#define MODEND 0x8A
#define EXTDEF 0x8C
#define TYPDEF 0x8E
#define PUBDEF 0x90
#define LINNUM 0x94
#define LNAMES 0x96
#define SEGDEF 0x98
#define GRPDEF 0x9A
#define FIXUPP 0x9C
#define LEDATA 0xA0
#define LIDATA 0xA2
#define COMDEF 0xB0 /* communal-names definition */
/********************************
* Intel Object Record Types *
********************************/
#define RHEADR 0x6E
#define REGINT 0x70
#define REDATA 0x72
#define RIDATA 0x74
#define OVLDEF 0x76
#define ENDREC 0x78
#define DEBSYM 0x7E
#define LHEADR 0x82
#define PEDATA 0x84
#define PIDATA 0x86
#define LOCSYM 0x92
#define LIBHED 0xA4
#define LIBNAM 0xA6
#define LIBLOC 0xA8
#define LIBDIC 0xAA
/************************
* Miscellaneous defines *
************************/
#define NUM_ARGS 2
#define MAX_LNAME_ENTRIES 100
#define MAX_NAME_LEN 64
#define MAX_SNAME_ENTRIES 100
#define SNAME_SEG 0
#define SNAME_CLASS 1
#define SNAME_OVL 2
#define GRPDEF_SI 0xff
#define CV_ARRAY 0x6281 /* Codeview array indicator? */
#define BLANK ' '
#define ZERO 0x00
#define NOSWAP 00
#define SWAP 01
#define BIT7 0x80
#define BIT6 0x40
#define BIT5 0x20
#define BIT4 0x10
#define BIT3 0x08
#define BIT2 0x04
#define BIT1 0x02
#define BIT0 0x01
/*********************
* Error code defines *
*********************/
#define USAGE_ERR 1
#define OPEN_ERR 2
/*********
* Macros *
**********/
#define MALLOC(x) ((x *) malloc(sizeof(x)))
#define CALLOC(n,x) ((x *) calloc(n, sizeof(x)))
/***********
* Typedefs *
************/
typedef unsigned char byte;
typedef unsigned char * p_byte; /* pointer to a byte */
typedef unsigned short word;
typedef unsigned short * p_word; /* pointer to a word */
/****************
* File pointers *
****************/
FILE *fp1; /* object code file pointer */
/*******************
* Global variables *
*******************/
word stoppit; /* flag for end of file */
word i=0,j=0,k=0; /* misc index counters */
byte c=0,c1=0,c2=0; /* misc unsigned char variables */
word reclen=0; /* length of record */
byte num_bytes=0; /* length of string passed */
word chksum_count=0; /* total bytes read for a record */
byte chksum=0; /* the checksum from the obj file */
byte Lnames_index=1; /* number of LNAMES entries */
byte Lnames_total=0; /* number of LNAMES entries */
/* storage for LNAMES data */
byte Lnames [MAX_LNAME_ENTRIES] [MAX_NAME_LEN+1] =
{'*','N','U','L','L','*','\0'};
byte Snames_index=1; /* number of SNAMES entries */
byte Snames_total=0; /* number of SNAMES entries */
/* storage for SNAMES data */
word Snames [MAX_SNAME_ENTRIES] [SNAME_OVL+1] =
{ {0,0,0} };
byte *align_msg[] = /* SEGDEF align messages */
{
"0 Absolute segment",
"1 Relocatable and byte-aligned segment",
"2 Relocatable and word-aligned segment",
"3 Relocatable and paragraph-aligned segment",
"4 Relocatable and page-aligned segment",
};
byte *combine_msg[] = /* SEGDEF combine messages */
{
"0 Private segment",
"1 ?",
"2 Public segment",
"3 ?",
"4 ?",
"5 Stack segment",
"6 Common segment",
};
byte chr_buff[256]; /* string buffer */
/**************************************************************
* This program uses the Object Record Types as described in *
* the following documents : *
* *
* Intel : 8086 Relocatable Object Module Formats *
* Version 4.0, Order # 121748-001 *
* Microsoft : MS-DOS Programmers Reference *
* Document # 8411-310-02 *
* Part # 036-014-012 *
***************************************************************/
word main(argc,argv)
word argc;
byte *argv[];
{
void do_blkdef(void);
void do_blkend(void);
void do_comdef(void);
void do_coment(void);
void do_extdef(void);
void do_fixupp(void);
void do_grpdef(void);
void do_ledata(void);
void do_lidata(void);
void do_linnum(void);
void do_lnames(void);
void do_modend(void);
void do_pubdef(void);
void do_locsym(void);
void do_segdef(void);
void do_theadr(void);
void do_typdef(void);
void do_unimplt(void);
void exit(int);
byte get_obj_byte(void);
if (argc != NUM_ARGS)
{
fputs("Usage: readobj filename \n", stderr);
exit(USAGE_ERR);
}
if ((fp1 = fopen(argv[1], "rb")) == NULL)
{
fprintf(stderr,"Can't open %s\n",argv[1]);
exit(OPEN_ERR);
}
printf("READOBJ by Kip Davidson (73247,620)\n");
printf("\tOS/2 version Dave Cortesi (72155,450)\n\n");
c = get_obj_byte();
while (stoppit == 0)
{
switch (c)
{
case BLKDEF :
do_blkdef();
break;
case BLKEND :
do_blkend();
break;
case THEADR :
do_theadr();
break;
case COMENT :
do_coment();
break;
case MODEND :
do_modend();
break;
case EXTDEF :
do_extdef();
break;
case TYPDEF :
do_typdef();
break;
case PUBDEF :
do_pubdef();
break;
case LOCSYM :
do_locsym();
break;
case LINNUM :
do_linnum();
break;
case LNAMES :
do_lnames();
break;
case SEGDEF :
do_segdef();
break;
case GRPDEF:
do_grpdef();
break;
case FIXUPP :
do_fixupp();
break;
case LEDATA :
do_ledata();
break;
case LIDATA :
do_lidata();
break;
case COMDEF :
do_comdef();
break;
case 0x00 : /* null bytes used in LIB files for padding */
break; /* skip 'em, a THEADR will show up soon */
default :
do_unimplt();
break;
}
c = get_obj_byte();
}
return(0);
}
/************************************************
* get a byte from the object code file pointer *
************************************************/
byte get_obj_byte()
{
word w;
c = (byte)(w = getc(fp1));
stoppit = (w == EOF);
chksum_count = chksum_count + c;
return(c);
}
/************************************************
* get a word from the object code file pointer *
************************************************/
word get_obj_word(swap)
byte swap;
{ /* input - Hi Lo */
if (swap)